home *** CD-ROM | disk | FTP | other *** search
/ MacWorld Ultimate Mac / Macworld Ultimate Mac CD-ROM (1994)(IDG).iso / The Best of BMUG / Utilities / Control Panels and Extensions / ClipboardMagician.76 / About Clipboard Magician next >
Text File  |  1990-12-11  |  28KB  |  167 lines

  1. Clipboard Magician 0.65                                1990-12-11
  2.                                                         by Ed Lai
  3. • not an Apple Computer, Inc. product •     lai@apple.com, AppleLink: Lai1
  4. -----------------------------------------------------------------
  5. •••  dedicated to all those, who fight for democracy in China •••
  6. -----------------------------------------------------------------
  7.  
  8. The goal of CM 0.65 is to make easier to work with other application. The reason that CM chooses to work with the clipboard is that it is possible to use CM functionality from any application through the clipboard. However very often you still have to go through the following steps:
  9. 1. Select the data of interest to you in your application and then do copy.
  10. 2. Invoke the DA.
  11. 3. Select and perform the operation.
  12. 4. Close the DA to get back to your application.
  13. 5. Paste the result in.
  14.  
  15. Potentially you can do all these with a single key stroke in 0.65.
  16.  
  17. For this purpose there are two new FKEYs that can be used with CM.
  18.  
  19. FKEY 6 just invokes CM. So you can get to CM with a single key stroke.
  20.  
  21. FKEY 5 copy the content of the current selection in your application
  22. into the clipboard and then invoke FKEY 6. This means that if you use FKEY 5, CM would be invoked with the content of the current selection in your application.
  23.  
  24. So these FKEYs combines steps 1 and 2 into a single key stroke.
  25.  
  26. CM now remembers the last operation you did, on the assumption you
  27. are very likely to do it again. It will be the default selection whenever the data type matches.
  28.  
  29. So if you want to apply the last operation one more time using the FKEYs, the amount of work required in step 3 is reduced.
  30.  
  31. We have added two new checkboxes. With a total of 5 checkboxes it is getting to be a bit crowded so the checkbox  text has to be greatly shortened. However the five checkbox will be duplicated by a menu item with a fuller title. While this is a duplication, the reason for doing this is that there is wide spread disagreement on the first prototype whether an item should be a checkbox or on the menu. If it is on a checkbox it gives visual feedback of the state and it can be accessed quickly with the mouse. If it is on the menu, the title can be longer and it can be invoked from the keyboard with a command key (starting with 0.65 keyboard shortcut on the CM menu will be handled even though I have not put any up there, you can add it yourself). So with the duplication you can have it both ways.
  32.  
  33. The first of the check box is Auto-run. If this is on then when the DA is first opened, if the last operation on the clipboard can be operated on by the last operation you did on CM, it would be invoked automatically. This would simplify step 3 above even further. However initial feedback is while this is powerful its is also dangerous because you may not remember what your last operation is and you are plunging into the unknown. The answer to  that is that this is an option that you should turn on only on special situation. Then you repeat the operation a number  of times and then turn it off again so you need not remember what was your last operation on CM 2 weeks ago before your vacation. Furthermore this option is now more restrictive than the first prototype (I may relax them again in future depending on the feedback on this version). It would only occur if the DA is not yet opened. And after you select this option the option would be turned off automatically if you select some other operation after that. The idea being that you want to select the auto-run option right after an operation when your mind is still fresh about what that operation is. If you go on to do some other things, you may not remember it so we turn it off for you. As an additional reminder what this operation is, you can pull down the CM menu to see exactly what the name of the operation is.
  34.  
  35. So with auto-run, we can eliminate step 3 above, now we want to eliminate step 4 and 5. This is the purpose of the other new checkbox Auto-quit. If both auto-run and auto-quit are selected, then after the auto-run is successfully  executed, the DA would close itself and post a command-V so that the clipboard data will be pasted back into your application's selection. 
  36.  
  37. So now it is possible to perform step 1 to step 5 with a single keystroke using FKEY 5. It look just like it is an extension of your application. Actually the integration could even be better. Currently it still goes through every step as if you have invoked a macro to bring up the DA, select the operation and close it so you are aware that you are doing it through a DA. A lot of these could have been bypassed so you may not realize that this is functionality from somewhere else, and the performance would be much better, but this will not be attempted in this version.
  38.  
  39. One question remains, if CM is on such auto-pilot, how can you regain control so that you can do something else with it. You can do that by holding down the shift key when you invoke CM, then the auto-run will not be executed. However do not hold down the command key at the same time. This is because command + shift key down would not disable auto-run so that FKEY 5 would still work even if you hold down the command shift keys for too long.
  40.  
  41. Another new feature is that when you are in CM, after you have done various thing you have decided to execute an operation will bring you a result that can be pasted back to your application. Then execute that operation with the command key down, that would execute the operation, close the DA and post a command-V.
  42. If the DA is run under system 7, the coercion routine in the AppleEvents manager will be used to convert the numeric data type into text string.
  43.  
  44. These are the new features in the DA. As for the CNVTs in the Magic Wand file, there are relative few changes.
  45.  
  46. In the Edit Big file with no Wrap around, there is a very serious bug that double click to select a word crashes the system. As a temporary fix I have disabled double click but but I forgot to put it in version 0.64, so I put it in this time. In the print text CNVT, it has been extended to do multiple "columns". When you invoke it using the options keys, one of the option would be a layout that you can pick. The layout is just a 'nrct' resource so you can make your own custom one by editing the resource (where each rectangle represents a "column" all of which must have the same width, and if there is a rectangle that enclose all other rectangles then that enclosing rectangle is not used for printing but will be used to represents the page so that there can be margins for the "columns").
  47.  
  48. There is a new CNVT to convert an error number into a text string. This will also be used by CM to return more meaningful error message. However the list of errors is far from complete but may be added by ResEdit.
  49.  
  50. We have a contribution from Maf Vosburgh to dither color picture to B/W.
  51.  
  52. Gestalt let you find out about the Gestalt of your system, the four letter code should be TEXT data in the clipboard.
  53. AECoerce can be used if you have system 7 to do a conversion using AppleEvents Manager's coercion routines.
  54. AToB let you do the AToB decoding used in some UNIX system.
  55. SGB to HGB conversion let you convert data from pre-6.03 Simplified Chinese system to 6.0x system.
  56. You may put a name in the clipboard and then get a resource with that name using a new CNVT.
  57.  
  58. As we have more and more CNVTs, keeping track of version is more and more painful, especially when we have deleted unused ones and add new customized ones. Also adding through ResEdit is painful because we are often adding a group of resources and they may need renumbering. So we add a installer utility this time. This is just the first time it is introduced so it is going to be a bit rough on the edges and it has been barely tested. It is model after the familiar model of font-DA mover so it should be easy to use. Like font-DA mover you should hold down option key to open a file if its file type is different from that of the magic wand. When you copy a CNVT over if the name already exists it would give you a warning and another warning if you try to replace a newer version to reduce the chance of mistake. Also any undated CNVT is considered to be very new to be on the safe side. When you copy a list of CNVTs, you may choose to always have such confirmations or ignore them automatically. Like DA movers, resource number will be assigned automatically. Very often names have been renamed or localized, so the utility cannot completely rely on the name to tell things apart. We shall use the rule that we use the 8 character tag ID to distinguish CNVTs, and only if the 8 byte tag is absent then we use the name. If you have localized the name or change it in some other way the tag name would still be same. We know you probably want to keep using the same name so the utility would not change that name even if it is different from the source file.
  59.  
  60.  
  61. ----------------------------------
  62.  
  63. About Clipboard Magician 0.64, 90-5-24.
  64.  
  65. The most important feature of this version of Clipboard Magician is that there is a protocol to support code resource other than CM's private type of 'CNVT'. Besides supporting a few popular code resources, it also enable the definition of a new code resource which is a batch file for a list of commands to be executed.
  66.  
  67. In this version of the CM commands are now listed alphabetically.  Furthermore, one can now select a command by typing in the first few letters as in any standard file dialog. For those who like to do everything from the keyboard, it is possible to use the tab key to switch between the clipboard view and the command view, and the esc key (shift tab or option tab if your keyboard does not have an esc key) to switch between data specific commands and commands that do not operate on any data. Thanks to Ian Feldman for these suggestion and other valuable contribution to CM.
  68.  
  69. There are several new menu items:
  70. 'page setup' - just like in most other applications.
  71. 'Do To All Data' -  if there are more than one piece of data in the clipboard, this would apply the selected command to every piece of data instead of just the selected data.
  72. 'Delete This Operation' - This is used to delete a code resource and all resources belong to that code resource according to the CM convention.
  73. `Start chaining/ End chaining' - see below.
  74.  
  75. This last one is used to define a custom command, formed by  selective chaining of a sequence of needed function commands. For example, a 'PICT' might be rotated by first converting it to a bitmap image ('bmap'), then rotating and, finally, converting it back to a 'PICT'.  If one does this often, then a special compound-operation command can be defined.  This is achieved by making CM remember the proper sequence of commands;  in this case -- put a 'PICT' in the clipboard, then choose the  'Start chaining' menu item.  Now do the commands in desired sequence, i.e.  convert to bmap, rotate, convert to PICT. Terminate the chaining process by selecting `End chaining'.
  76.  
  77. Next you'll be asked to name the new command, and enter information about the operation.  From now on, if you have a 'PICT' in the clipboard, you should see your custom command in the list of operations in the main window, among the ones that can be executed on the given resource type.  Selecting it will execute all the commands in the defined sequence.  Selecting it with the option key makes it step through the individual commands, for control or debugging purposes. However the "do it to all data" option is not registered in the chain in this version of CM.
  78.  
  79. Among the issues that this particular version of CM tries to solve is that of localization.  The commands' names may now be changed at will, to a foreign language or accordingly to taste.  However, commands DO call each other and if they are changed, they may no longer find one another.  With the ability to chain commands together, this problem become even more acute.  In this version, names of other commands are given an eight byte language independent signature so that it should be possible to call any renamed one in a language-independent way.  The proper signature can be found in the "About this operation" dialog (although not all commands have been assigned signatures yet).
  80.  
  81. The chain-command feature is implemented in such a way that the CM's architecture becomes wide open.  In previous versions, the commands were all CNVT code resource with certain calling conventions.  This, my latest, architecture makes any type of a code resource (with any calling convention) potentially usable by the CM.  Of course, it is not my philosophy to have built-in support for every single type of resource.  In this version there is still built-in direct support for only one kind of resources, that of the `CNVT' type.  However, now it is entirely possible to have other resources execute by means of appropriately written adapter CNVTs.  This is how the new command chaining is implemented.
  82.  
  83. Using the same mechanism, a few more resources types are now supported. They are XCMDs, XCFNs, FKEYs, VCMDs and VFILs.  Of course, since you are running within a DA and not in Hypercard proper, many XCMDs will not work, if they expect to query HyperCard during the execution (ie, call back to get a field by ID or similar).  Do expect a lot of XCMD and VCMDs not to work and even crashes when they try to access facilities available in their original environment but not available in CM. However, if the calls that they use are of fairly generic type, such as ones to convert a number to string, then the XCMD can be used here as well.  The XCMD must be first renamed to follow the CM-calling conventions though (This is also true of using any other code resources).  If, say, the original XCMD is called by 'xyz', then it should be copied and saved into the Magic Wand, renamed either as a 'TEXTxyz' resource, a '****xyz' or '____xyz' (if it doesn't require any arguments).  Study the (supplied here as an example only) original HyperCard 'Flash' XCMD, now called via the 'TEXTFlash' CM-command: entering the number '4' into the clipboard will make a 'Flash' appear as a possible "conversion" command in the CM's main window.  Selecting it passes the clip- board held argument to the embedded FlashXCMD, that will then flash the DA window 4 times.  This particular XCMD might not be that useful but, given the large number of XCMD available, I am sure that this feature will find its use.  For example, it helped me a lot when I was documenting the CNVT by running the XFCN 'Resource()'to return resource names for CNVT, prior to sorting/inventorying.
  84.  
  85. As each CNVT are being improved, it is difficult to know whether you are replacing a new version with an older version since there is no version information. In this version of CM, the create date of the resource is used as the version. This is append to the CNV! string. You can get the date from the "About This Operation" command. Also sometime it is useful to know what kind of result a CNVT may return. This information is also put into the CNV! and is shown by the "About This Operation".
  86.  
  87. Highlights of some of the new CNVTs
  88.  
  89. 'bmap' is the bitmap data, for which there is now a simple fat-bits editor; flipping and 90-degree rotation of bitmaps is also possible.  Resources of type ICON/ SICN/ PICT can now be easily changed to and from 'bmap' prior to editing, and then converted back to their original resource types.  Now one can also capture a portion of the screen and make it into a PICT (in monochrome 1-bit-per-pixel only).  Any block of memory can now be read in.  One may also enter special characters, using the C convention of \n \f etc (plus \$XX for hexadecimal) and then converting the strings to proper bytes.  A number of other CNVT resources uses this particular CNVT for their own entry needs for special characters -- like the Munger, the toolbox Munger call, that can be used to insert, delete or replace blocks of binary data. You can transpose a string of text into reverse order. Data can be sent through the serial port, and if you have a modem there and you configure the command right (as usual by holding down the option key and the command is invoked), you can use that to dial a number. You can now test a FKEY by copying it into the clipboard and then execute it. You can invoke FKEYs installed in the system folder. Since this feature is implemented as an FKEY, you can also used this FKEY (look for the FKEY with the name "___Invoke other FKEY") as an ordinary FKEY if you wish. This permits you to have more than the 10 FKEYs by assigning names to other FKEYs. This is not as nice as popkeys but is a little safer since no INIT is involved. We have two CNVTs - "Read EPSF file" and "Polygonize" that are contributed by Anders Blomdell. With Read resources, it is now possible to read more than one resource at a time.
  90.  
  91. ----------------------------------
  92.  
  93. About Clipboard Magician 0.55, 89-9-8.
  94.  
  95. In view of what has been happening in China, I am dedicating this program to all those who are fighting for democracy in China.
  96.  
  97. There is only minor modification of the DA from version 0.5 to 0.55. The change is made mainly so that an operation can now return a list of data rather than a single piece of data. The visiable change to the DA is that now the number of bytes in the data selected is displayed. If an operation has failed, an error number is also displayed (of course this will be change to error message in future).
  98.  
  99. The major change is more new components have been added. Now there are over 40 components with a total size of 87K. I shall give a list of all the components.
  100.  
  101. Convert ICON to PICT.
  102. Convert PICT to ICON.
  103. Convert CURS to PICT.
  104. Convert PICT to ICON.
  105. Reduce PICT to its edge.
  106. Convert PICT to SICN - from PICT to 16x16 bit map.
  107. Convert MWRT to TEXT - MacWrite data to plain text.
  108. Change carriage return in text to space.
  109. Remove line feed character from text.
  110. Save a PICT as PICT file.
  111. Read Text file into scrap.
  112. Read PICT file into scrap.
  113. Hexdump the data.
  114. Get file info.
  115. Convert STR to TEXT.
  116. Convert ICN# to PICT.
  117. Play a snd  resource sound.
  118. Rename the data type.
  119. Print a PICT.
  120. Print the TEXT; hold down option key to change font and size.
  121. Edit the text - function is about that of TeachText; hold down option key to change font and size.
  122. Read data fork of a file into scrap.
  123. Consider ICN# to be a list of icons and pick an icon out of the list.
  124. Read a resource from a file into the scrap.
  125. Save data as resource in an existing file.
  126. Pack hexdecimal digits.
  127. Save data into the data fork of a new file.
  128. Sort text lines.
  129. Append data to the data fork of an existing file.
  130. Read a MacPaint file into scrap as PICT.
  131. Select an area out of a PICT.
  132. Transliterate text - See inside Mac, vol 5, p311.
  133. Convert HyperCard card fields and buttons into a dialog item list DITL.
  134. Replace text string, uses Grep library from Capps'™ of Think Technologies Inc.
  135. Rotate SICN the 16 by 16 bit map.
  136. Rotate ICN#, a list of icons.
  137. Convert Shifted GB code Chinese character to GB code.
  138. Convert GB code to Shifted GB code Chinese character.
  139. Edit big text data that has no need of wrap around, uses PEEdit library from Capps'™ of Think Technologies Inc. Hold down option key to change font and size
  140. Generate some text and put it into scrap.
  141. Convert dialog item list DITL to view resource for use in MACAPP 2.0.
  142. Convert dialog item list DITL to a HyperCard card.
  143. Edit data according to a template, template is in same format as that of ResEdit. Read ResEdit manual for more details. There is also an extension to the template types. BBYT is boolean in a single byte. ATPX where x is '0'-'9' is align to the power. So ATP5 means align to the 2 ** 5 = 32 bytes, and 0 is treated as 10. No editing allowed if size of data is large. Hold down option key if you want to edit without a template (edit the hex dump).
  144. ----------------------------------
  145. About Clipboard Magician 0.5, 89-4-6.
  146.  
  147. The Clipboard Magician is a prototype written to explore certain concepts. I have worked on and off on the project, never quite finishing it.  However I have been using it myself daily without serious problem. I feel even in its present form it can be useful to many users. So I am releasing it as freeware. You may copy it and use it freely, but it may not be redistributed as a commercial product. Apple computer Inc. retains the copyright. NOTE THAT THIS IS NOT AN OFFICIALLY RELEASED PRODUCT FROM APPLE COMPUTER INC SO DO NOT EXPECT IT TO HAVE THE QUALITY AND ROBUSTNESS YOU NORMALLY EXPECT FROM PRODUCTS FROM APPLE COMPUTER INC., NOR EXPECT ANY SUPPORT ON THIS PROGRAM FROM APPLE COMPUTER INC.
  148.  
  149. The Clipboard Magician is a desk accessory that displays the scrap. It is just like a clipboard but it also allows you to manipulate the data there. The basic concept is that application should not be required to copy multiple representation to the scrap. Rather an application can copy the most meaningful information to the scrap, and tools can be used to transform it to other desired form. The Clipboard Magician cannot pull a rabbit out of the clipboard, but if you put an ICON into it, you can pull a PICT out of it. That is why it is called Clipboard Magician. (Earlier I have used the name Alchemist, the theme is similar). If you have copied an ICON using ResEdit, the current Finder Clipboard will not show it, neither will the scrapbook. However the Clipboard Magician would just transform it into a picture and show it.
  150.  
  151. Of course we would need more tools as new data type are introduced. Hence there is no fixed set of tools. Rather the tools are software components - XCMD like code resource - that are installed into a file called "Magic Wand" that should be placed in the system folder. So if you need to display a CURS, you need to get a CURS to PICT components. As needs arises, I have written a number of components for my own use. They are written in a quick and dirty manner (some are written in a few minutes) and certainly nothing worth bragging about individually. Do not judge the concept of the Clipboard Magician by the quality of component tools available here. They are no more than examples hinting what can be done. Hopefully better versions will be written and since they are components they can be replaced any time. Collectively they still represent a useful collection of tools that is available to the user anytime. This is especially useful if you are not running MultiFinder. I interpret the word conversion very broadly. PICT to ICON and ICON to PICT obviously are conversions. Removing line feeds from text data is also a conversion. So are text editing, text printing, picture printing, saving scrap data to file (either data fork or resource), reading data (either data fork or resource) into scrap (so you can hunt for ICONs from various applications), read a PICT/PAINT file to scrap, get file information, do a hex dump, undo a hex dump, play a 'snd ', all available from a single DA. And if you are willing to  program the component or someone else is doing it, it can be added to the list.
  152.  
  153. Install the Clipboard Magician DA and put the file "Magic Wand" into the system folder and you are ready to use it. When you open Clipboard Magician DA, there will be a list of all the data in the scrap, the data type is on the list so that you know what you are looking at. The main frame of the DA doubles as the clipboard view and command list, the default being the clipboard view. The two views can be toggled using the menu command Show Command/Show Clipboard View. A mouse click on the clipboard view also toggles it to the command view. If there are multiple data on the scrap, the view is selected by the selection in the list on the left. The commands also depend on the data type selected since different set of commands are available for different data types. If no data type is selected (this can also be done by selecting "generate new data" from the menu), then the command list will be those that generate data rather than operate on data, e.g. read MacPaint file into scrap. There is a check box on the DA to control whether picture will be shown as actual size or scaled to fit. Even in the background the DA would check for new content in the scrap periodically. So for an application that does not implement a clipboard and copies directly to the public scrap rather than keeping a private scrap, you can use the Clipboard Magician as a substitute clipboard. However to do this you should launch Clipboard Magician in the application partition under multifinder. One example is ResEdit. ResEdit copies to the public scrap, does not have a clipboard,  and does not generate extra PICT scrap data when ICON, CURS etc are copied. The Clipboard Magician would work nicely here as a clipbboard. If the Clipboard Magician is present in every system, no future application needs to implement a clipboard of its own.
  154.  
  155. When a command is selected, if the About this operation menu item is enabled, you can find out more about the command. To execute the command, you hit the "Do it" button (or double click on the command, or hit the return key). Normally the scrap will be cleared and the scrap will contain the new converted data. This can be changed by the checkbox so that the new data will be appended to the end of scrap. There are a few commands, like the text editor, that use certain default parameters (Font and size in this example). If you want to change the default, you should hold down the option key when you invoke the command.
  156.  
  157. There is currently no installer program for the components, so you have to use ResEdit to put it into file "Magic Wand" (I think you can even use the Clipboard Magician tools to do it if you are brave enough). The components are either of resource type CNVT or XRTN where the former are visible to the user and the latter is not accessible directly but may be used by the CNVT components. By convention the resource IDs are multiple of 32 and components with resource ID N would own all the resource with ID between N and N+31 (is that too few or too many?). The resource name of CNVT has to follow certain convention so be careful when you try to translate it into a foreign language. The first four byte is the data type that the command can operate on (or ____ if it does not operate on any data, or **** if can operate on any kind of data as in the case of hexdump). If the fifth byte is '>' followed by four more bytes, then it is a data conversion component and should not be renamed. Otherwise the rest is just the command name and you can change or translate it. However some of the components may be called by other components by name (in particular the text and pict printing components are called by the Clipboard Magician to print the clipboard), changing the name may make other components fail.
  158.  
  159. In a sense the paradigm is a pseudo-object-oriented approach where the data type is the class, '****' is the superclass. You select an object and the methods (including those inherited from the superclass) are presented. It is a nice paradigm. However there are newer applications that paste different types of data to the scrap where one is the supplement of the other. An example is 'styl'. Then the current paradigm breaks down. Fortunately they are comparatively rare. Actually this comes about because the convention of writing multiple sets of data to the scrap is wasteful and this is used as a way of getting around the problem. This won't be necessary if we follow the Clipboard Magician paradigm where application just write out the richest data type, and the Clipboard Magician would convert it to a form acceptable by other applications.
  160.  
  161. The Clipboard Magician requires the 128K ROM. The DA is about 10K. The current magic wand file is 31K and contains 30 components, only a few needs to be in memory at the same time. There is a separate document on how to program CNVTs.
  162.  
  163. Send bug report or comments or new components to
  164. Ed Lai
  165. lai@apple.com
  166. AppleLink: Lai1
  167.